const { Service } = require("egg");
class RecommendGoodsService extends Service {
  // 获取推荐商品
  async getRecommendGoods() {
    const { ctx } = this;
    const res = await ctx.model.RecommendGoods.aggregate([
      {
        $lookup: {
          from: "Goods",
          localField: "goodsId",
          foreignField: "_id",
          as: "goodsData",
        },
      },
      {
        $unwind: "$goodsData",
      },
      {
        $project: {
          _id: 1,
          cover: 1,
          name: "$goodsData.name",
          goodsId: "$goodsData._id",
          price: "$goodsData.price",
          visitTimes: 1,
          recommendDate: 1,
          saleIncr: 1,
          dayAvgIncr: 1,
          sort: 1,
          categoryId:1
        },
      },
      {
        $sort: { sort: 1 }
      }
    ]);
    return {
      mes: "成功",
      data: res,
    };
  }
}
module.exports = RecommendGoodsService;
